package edu.xlh.travel.controller.user;

import com.alipay.api.AlipayApiException;
import edu.xlh.travel.common.Result;
import edu.xlh.travel.service.ForeHotelOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.HashMap;

@Controller
@RequestMapping("/fore_hotelOrder")
public class ForeHotelOrderController {
    @Autowired
    private ForeHotelOrderService foreHotelOrderService;

    /*
    * buy ticket
    * */
    @RequestMapping("/buy")
    @ResponseBody
    public Result buy(@RequestBody HashMap<String,Object> hotelHashMap , HttpSession session) {
        return foreHotelOrderService.buy(hotelHashMap , session);
    }

    /*
    * */
    @RequestMapping("/findAllOrders")
    @ResponseBody
    public Result findAllOrders(HttpSession session) {
        return foreHotelOrderService.findAllOrders(session);
    }

    @RequestMapping("/cancelOrder")
    @ResponseBody
    public Result cancelOrder(String orderId , HttpSession session) {
        return foreHotelOrderService.cancelOrder(orderId , session);
    }

    /*
     * to orderPay page And callBack orderInfo by orderId
     * */
    @RequestMapping("/toPayOrderPage")
    public String toPayOrderPage(String orderId , HttpSession session , Model model) {
        System.out.println("订单号"+orderId);
        return foreHotelOrderService.toPayOrderPage(orderId , session , model);
    }

    @PostMapping(value = "/doPayForOrder" , produces = "text/html; charset=UTF-8")
    @ResponseBody
    public String doPayForOrder(@RequestBody HashMap<String,String> orderInfo , HttpSession session) throws AlipayApiException {
        return foreHotelOrderService.doPayForOrder(orderInfo , session);
    }


    /*
     * determine 确定入住
     * */
    @RequestMapping("/determine/{orderId}" )
    @ResponseBody
    public Result determine(@PathVariable("orderId") String orderId , HttpSession session) {
        return foreHotelOrderService.determine(orderId , session);
    }

    /*
    * find by orderId
    * */
    @RequestMapping("/findByOrderId/{orderId}/{emailId}" )
    @ResponseBody
    public Result findByOrderId(@PathVariable("orderId") String orderId , @PathVariable("emailId") String emailId , HttpSession session) {
        return foreHotelOrderService.findByOrderId(orderId , emailId , session);
    }

    /*
    * 续租 relet
    * */
    @RequestMapping("/relet/{orderId}" )
    @ResponseBody
    public Result relet(@PathVariable("orderId") String orderId, @RequestBody HashMap<String , String>hashMap , HttpSession session) {
        return foreHotelOrderService.relet(orderId  , hashMap , session);
    }

}
